package com.starmark.gateway.log.access.web;

import com.starmark.auth.common.util.UserUtil;
import com.starmark.core.framework.base.AbstractController;
import com.starmark.core.framework.util.BeanMapper;
import com.starmark.gateway.log.access.entity.GatewayAccessLog;
import com.starmark.gateway.log.access.service.IGatewayAccessLogService;
import com.starmark.gateway.log.access.vo.GatewayAccessLogPageVo;
import com.starmark.gateway.log.access.vo.GatewayAccessLogVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 系统访问日志 前端控制器
 * </p>
 *
 * @author starmark
 * @since 2018-12-15
 */
@RestController
@Api(value = "系统访问日志管理", description = "系统访问日志管理")
@RequestMapping("gateway/log/access")
public class GatewayAccessLogController extends AbstractController {
    @Autowired
    IGatewayAccessLogService accessLogService;

    @ApiOperation(value = "查询系统访问日志列表")
    @PostMapping(value = "/query")
    public Object query(@RequestBody Map<String, Object> param) {
        param.put("projectCode", UserUtil.getCurrentUser().getProjectCode());
        return BeanMapper.mapPage(accessLogService.query(param), GatewayAccessLogPageVo.class);
    }


    @ApiOperation(value = "系统访问日志详情")
    @GetMapping(value = "/{id}")
    public Object get(@PathVariable("id") String id) {
        GatewayAccessLog gatewayAccessLog = accessLogService.getById(id);
        return BeanMapper.map(gatewayAccessLog, GatewayAccessLogVo.class);
    }


    @DeleteMapping(value = "/{id}")
    @ApiOperation(value = "删除系统访问日志")
    public void delete(@PathVariable("id") String id) {

        accessLogService.removeById(id);
    }

}
